/ leetcodesolve / 852. Peak Index in a Mountain Array.py
swadhinbiswas update on more problem solving · 2/16/2025
3fc0eac
17 lines · 394 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution:
    def peakIndexInMountainArray(self, arr: List[int]) -> int:
        start=1;end=len(arr)-2
        while(start<=end):
            mid=start+(end-start)//2
            if arr[mid-1]<arr[mid] and arr[mid]>arr[mid+1]:
                return mid 
            elif arr[mid-1]<arr[mid]:
                start=mid+1
            else:
                end=mid-1
        return -1